home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue31 / construc / BOBSPELL.DPR < prev    next >
Encoding:
Text File  |  1998-02-06  |  2.0 KB  |  85 lines

  1. {$A+,B-,D-,E-,F-,G-,I-,L-,N-,O-,P-,Q-,R-,S+,T-,V+,X+,Z-}
  2. {$APPTYPE CONSOLE}
  3. program BobSpell;
  4. uses
  5.   Engine, BobSpDlg, Controls;
  6.  
  7. const
  8.   MaxNode = 4429;
  9.  
  10. var
  11.   Nodes: Array[1..MaxNode] of ShortString;
  12.   Words,i,j: Integer;
  13.   Str: ShortString;
  14.   IndexFile: Text;
  15.  
  16.   function IndexOf(const Name: ShortString): Integer;
  17.   var
  18.     Max,Min,Tmp: Integer;
  19.   begin
  20.     Result := 0;
  21.     Min := 1;
  22.     Max := MaxNode;
  23.     repeat
  24.       Tmp := (Min + Max) div 2;
  25.       if Nodes[Tmp] < Name then Min := Tmp
  26.       else
  27.         if Nodes[Tmp] > Name then Max := Tmp
  28.         else
  29.           Result := Tmp
  30.     until ((Max - Min) <= 1) or (Result > 0)
  31.   end {IndexOf};
  32.  
  33. begin
  34.   Assign(IndexFile,'wordlist');
  35.   Reset(IndexFile);
  36.   Words := 0;
  37.   while not eof(IndexFile) do
  38.   begin
  39.     Inc(Words);
  40.     readln(IndexFile,Nodes[Words])
  41.   end;
  42.   Close(IndexFile);
  43.  
  44.   with TFormBobSpell.Create(nil) do
  45.   try
  46.     write('Give word to spell-check: ');
  47.     readln(Str);
  48.     writeln;
  49.     i := IndexOf(Str);
  50.     if i > 0 then writeln('Exact Match at wordlist position ',i)
  51.     else
  52.     begin
  53.       i := 0;
  54.       ListBoxSuggestions.Items.Clear;
  55.       EditFrom.Text := Str;
  56.       EditTo.Text := Str;
  57.       repeat
  58.         Inc(i);
  59.         j := Diff(Str,Nodes[i]);
  60.         if j = 1 then
  61.           ListBoxSuggestions.Items.Add(Nodes[i])
  62.       until (i >= Words) or (j = 0);
  63.       if j = 0 then writeln('Match at ',i,': ',Nodes[i])
  64.       else
  65.       begin
  66.         if ShowModal = mrOk then
  67.         begin
  68.           case Action of
  69.          Ignore: writeln('Ignoring ',Str);
  70.       IgnoreAll: writeln('Ignore All ',Str);
  71.         Replace: writeln('Replace ',Str,' with ',EditTo.Text);
  72.      ReplaceAll: writeln('Replace All ',Str,' with ',EditTo.Text);
  73.             Add: writeln('Add ',Str,' to wordlist');
  74.             else writeln('No Action'); {None}
  75.           end
  76.         end
  77.         else
  78.           writeln('No Action')
  79.       end
  80.     end
  81.   finally
  82.     Free
  83.   end
  84. end.
  85.